#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/2/6
# @Author: Sunny
# ========================

"""
自己手动实现一个操作文件的上下文管理器类
"""


class MyOPen:

    def __init__(self, filename, mode, encoding='utf-8'):
        self.f = open(filename, mode, encoding=encoding)

    def __enter__(self):
        return self.f

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.f.close()
        print(exc_type)
        print(exc_val)
        print(exc_tb)


print()

with MyOPen('text.txt', 'w') as f2:
    f2.write('python1111111')
